<?php

//特点：传递不同的参数获取不同的对象
class ProductsA{

}
class ProductsB{

}

// 工厂模式
class ProductsFactory{
    public function create($num){
        switch ($num){
            case 1:
                return new ProductsA;
            case 2:
                return new ProductsB;
            default:
                return null;
        }
    }
}

// 测试
$factory = new ProductsFactory();
$obj1 = $factory->create(1);
$obj2 = $factory->create(2);

var_dump($obj1,$obj2);